package main

import (
	"context"
	"time"

	pb "goods-client/proto"

	"github.com/go-micro/plugins/v4/registry/consul"
	"go-micro.dev/v4"
	"go-micro.dev/v4/logger"
	"go-micro.dev/v4/registry"
)

var (
	service = "goods"
	version = "latest"
)

func main() {
	// 集成 consul,
	consulReg := consul.NewRegistry(registry.Addrs("127.0.0.1:8500")) // ==> "go-micro.dev/v4/registry"
	// Create service

	srv := micro.NewService(micro.Registry(consulReg))

	srv.Init()

	// Create client
	c := pb.NewGoodsService(service, srv.Client())

	for {
		// Call service
		rsp, err := c.AddGoods(context.Background(), &pb.AddGoodsReq{Title: "shop", Price: 12.33, Content: "content"})
		if err != nil {
			logger.Fatal(err)
		}

		logger.Info(rsp)

		time.Sleep(1 * time.Second)
	}
}
